package com.zdsoft.blp.zongbuju.shouye.linliquan.activity;

import android.content.Intent;
import android.text.Html;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.API.API;
import com.zdsoft.blp.gongyong.fanhui.FanHuiView;
import com.zdsoft.blp.gongyong.imageFrame.IvFrameView;
import com.zdsoft.blp.gongyong.net.BaseActivity;
import com.zdsoft.blp.gongyong.net.Net;
import com.zdsoft.blp.gongyong.net.NetCallback;
import com.zdsoft.blp.zongbuju.shouye.linliquan.adapter.LLPingLunAdapter;
import com.zdsoft.blp.zongbuju.shouye.linliquan.entity.LinLi;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/1.
 */
public class XQSCActivity extends BaseActivity implements NetCallback {
    private TextView es_title,es_time,es_jiage,es_fenlei,es_lianxiren,ershou_phone,es_content,es_pinglun;
    private ListView lv;
    private ImageView pinglun;
    private List<LinLi> list;
    private Intent intent;
    private FanHuiView fh;
    private IvFrameView iv;
    private String id, huifuTime,huifuUser,huifuImage,huifuContent;;
    @Override
    protected void init() {
        setContentView(R.layout.linli_ershouxiangqing);
        es_time = find(R.id.es_time);
        es_title = find(R.id.es_title);
        es_jiage = find(R.id.es_jiage);
        es_fenlei = find(R.id.es_fenlei);
        es_lianxiren = find(R.id.es_lianxiren);
        ershou_phone = find(R.id.ershou_phone);
        es_content = find(R.id.es_content);
        es_pinglun = find(R.id.es_pinglun);
        pinglun = find(R.id.pinglun);
        lv = find(R.id.es_xlv);
        lv.setFocusable(false);
        fh = find(R.id.fh);
        iv = find(R.id.iv);
        fh.getTv_title().setText("二手详情");
        //iv.show(new String[]{"http://img06.tooopen.com/images/20160830/tooopen_sy_177190512837.jpg", "http://img05.tooopen.com/images/20150730/tooopen_sy_136053335664.jpg", "http://img05.tooopen.com/images/20150730/tooopen_sy_136053335664.jpg"});

//        设置ListView不能滑动
        lv.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        //接收数据
        intent=getIntent();
        id=intent.getStringExtra("id");
        getNet();//实例化Net的方法

        pinglun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent=new Intent(XQSCActivity.this,LLHFActivity.class);
                intent.putExtra("id","3");
                startActivity(intent);
            }
        });
    }





    public void getNet() {
        Net net=new Net();
        net.url= API.ESINFO_URL;
        net.nameSpace=API.ESINFO_NAMESPACE;
        net.methodName=API.ESINFOCONTENT;//esInfoContent
        Map map=new HashMap();
        map.put("id",id);
        net.parms=map;
        getServer(net,this);

    }
    //回调函数
    @Override
    public void onResponse(boolean flag, int code, String res) {
        Log.e("转让",res);
        try {
            JSONObject object=new JSONObject(res);
            es_time.setText(object.getString("createTime"));
            ershou_phone.setText(object.getString("contactPhone"));
            boolean picPathSet= object.isNull("picPathSet");
            if (picPathSet==false){
                JSONArray array=object.getJSONArray("picPathSet");
                for (int i=0;i<array.length();i++){
                    JSONObject obj=array.getJSONObject(i);
                    String image= obj.getString("picPath");
                    if (!"".equals(image)){
                        iv.setVisibility(View.VISIBLE);
                        iv.show(new String[]{image});
                    }else {
                        iv.setVisibility(View.GONE);
                    }

                }
            }
            es_lianxiren.setText(object.getString("contact"));
            es_jiage.setText(object.getString("price"));
            es_fenlei.setText(object.getString("typeName"));
            es_content.setText(Html.fromHtml(object.getString("content")));
            es_pinglun.setText(object.getString("replyNum"));
            es_title.setText(object.getString("title"));
            boolean pingL=object.isNull("replySet");
            if (pingL==false){
                list=new ArrayList<>();
                LinLi pinche=null;
                JSONArray pingLun=object.getJSONArray("replySet");
                for (int i=0;i<pingLun.length();i++){
                    JSONObject pc_huifu=pingLun.getJSONObject(i);
                    huifuUser=pc_huifu.getString("replyUserName");
                    huifuTime=pc_huifu.getString("replyTime");
                    huifuContent=pc_huifu.getString("content");
                    huifuImage=pc_huifu.getString("replyUserHeadimgurl");
                    pinche=new LinLi(huifuUser,huifuContent,huifuImage,huifuTime);
                    list.add(pinche);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        // //实例化XListView
        LLPingLunAdapter adapter = new LLPingLunAdapter(list, getApplicationContext());
        lv.setAdapter(adapter);

    }
}
